<%--
  Created by IntelliJ IDEA.
  User: zhaolipeng
  Date: 2017-11-21
  Time: 10:17
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles" %>
<c:set var="basePath" value="//${header['host']}${pageContext.request.contextPath}/" scope="session"/>
<!DOCTYPE html>
<html>
<head>
  <base href="${basePath}">
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
  <link rel="shortcut icon" href="#" type="image/png">
  <title>掌上黄金管理后台</title>
  <link href="https://cdn.bootcss.com/element-ui/2.0.4/theme-chalk/index.css" rel="stylesheet">
  <link href="static/css/dev/common.css" rel="stylesheet">
  <script src="https://cdn.bootcss.com/vue/2.5.3/vue.min.js"></script>
  <script src="https://cdn.bootcss.com/element-ui/2.0.4/index.js"></script>
  <script src="https://cdn.bootcss.com/axios/0.17.1/axios.min.js"></script>
  <script src="static/js/dev/common.js"></script>
</head>
<body>
<div id="login" class="wrapper">
  <div class="login-wrap">
    <div class="ms-title">掌上黄金管理后台</div>
    <div class="ms-login">
      <el-form :model="loginForm" :rules="rules" ref="loginForm" label-width="0px" class="demo-ruleForm">
        <el-form-item prop="loginName">
          <el-input v-model="loginForm.loginName" placeholder="请输入登录名"></el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input type="password" placeholder="请输入密码" v-model="loginForm.password" @keyup.enter.native="submitForm('loginForm')"></el-input>
        </el-form-item>
        <div class="login-btn">
          <el-button type="primary" @click="submitForm('loginForm')" :loading="loginBtnLoading">登录</el-button>
        </div>
      </el-form>
    </div>
  </div>
</div>
</body>
<script>
  new Vue({
    el: '#login',
    data: function() {
      return {
        loginBtnLoading: false,
        loginForm: {
          loginName: '',
          password: ''
        },
        rules: {
          loginName: [{
            required: true,
            message: '请输入用户名',
            trigger: 'blur'
          }],
          password: [{
            required: true,
            message: '请输入密码',
            trigger: 'blur'
          }]
        }
      }
    },
    methods: {
      submitForm: function (formName) {
        const self = this;
        this.$refs[formName].validate(function (valid) {
          if (valid) {
            self.login();
          } else {
            console.log('error submit!!');
            return false;
          }
        });
      },
      login: function () {
        const self = this;
        this.loginBtnLoading = true;
        http.post("/emp/login", this.loginForm)
          .then(function (res) {
            window.location.href = "${basePath}emp/index";
          }).catch(function (error) {
            self.loginBtnLoading = false;
          });
      }
    }
  })
</script>
</html>
